Skip to content

Fix hiera.yaml write race in the pupmod spec_helper template - #91

Open
silug wants to merge 2 commits into
simp:mainfrom
silug:fix/hiera-yaml-write-race
Open

Fix hiera.yaml write race in the pupmod spec_helper template#91
silug wants to merge 2 commits into
simp:mainfrom
silug:fix/hiera-yaml-write-race

Conversation

@silug

@silug silug commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closes #90.

Every parallel_spec worker's before(:all) hook truncate-rewrites the shared spec/fixtures/hieradata/hiera.yaml; a catalogue compile in another worker during the truncation window sees an empty hiera config and silently drops all custom hieradata. That's the source of the fleet's random hieradata-not-applied spec failures (simp/pupmod-simp-simplib#362, simp/pupmod-simp-rsyslog#211, and the earlier freeradius/simp_options/tftpboot/gnome/ssh/sssd "flakes"). The fix writes hiera.yaml atomically (write to a pid-suffixed tempfile + rename).

Validated on simp/pupmod-simp-simplib#363 (merged): the module with the highest observed flake rate, green with the fixed helper.

Rollout, per the usual convention, ships in the same PR: session config 20260820-spec-helper-race.yaml (now latest) — a blanket apply_puppet_role session, safe again since #42. Because the baseline was just re-asserted fleet-wide, each repo's diff is exactly the atomic-write hunk (verified by a local e2e apply against a real pupmod-simp-aide clone); simplib already carries the fix and will come out unchanged.

Rebased onto main (post-#42, so the template base is current); the rendered non-simpkv template is byte-identical to simplib's validated in-repo copy. 215 rspec + 26 BoltSpec examples green; both EPP render branches are valid Ruby.

🤖 Generated with Claude Code

silug and others added 2 commits August 20, 2026 16:27
The config-level before(:all) hook rewrites
spec/fixtures/hieradata/hiera.yaml with a truncating write before every
top-level example group. Under `rake parallel_spec`, every worker runs
this hook, and a catalogue compile in another worker that reads
hiera.yaml inside the truncate-to-write window sees an empty hiera
config and silently compiles without any custom hieradata.

This is the confirmed root cause of the fleet-wide random
hieradata-not-applied spec failures (ref simp#90) — not the set_hieradata
global-state design originally suspected. Reproduced deterministically
in pupmod-simp-simplib by rewriting hiera.yaml in a tight loop while
running dlookup_spec (simp/pupmod-simp-simplib#362, fixed there by
simp/pupmod-simp-simplib#363 with this same change).

Write the file atomically instead: write to a PID-suffixed temp file in
the same directory and rename it into place. Readers then always see a
complete hiera.yaml. The temp file must be in the same directory --
rename(2) is only atomic within a filesystem.

Ref simp#90

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@silug
silug force-pushed the fix/hiera-yaml-write-race branch from 25104bb to fd3be0f Compare August 20, 2026 16:29
@silug
silug marked this pull request as ready for review August 20, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared spec_helper's set_hieradata global-state design causes random hieradata-not-applied spec failures fleet-wide

1 participant